<?php

/**
 * @author      : PhuongTN
 * @version     : 2012
 * @copyright   : FO
 * @name        : hethao_modules_block_business_block_metadata_layout
 * @todo        : Format data for layout
 */
class Fpt_Business_Block_Metadata_maplayoutsection
{
    /**
     *
     * @var int
     */
    private $LayoutName     = '';
    private $SectionName    = '';
    private $Module         = '';
    private $Controller     = '';
    private $Action = '';
    private $CateID = 0;
    private $MapParams = '';
    private $MapName = '';
    private $MapLayout = '';
    private $MapOrder = 0;
    private $CreateDate     = 0;
    private $ModifyDate     = 0;
    private $Status = 0;
    /**
     * `LayoutName` int(11) NOT NULL,
  `SectionName` varchar(30) NOT NULL DEFAULT '' COMMENT 'safename',
  `CreateDate` int(11) NOT NULL,
  `ModifyDate` int(11) NOT NULL,
  `Module` varchar(50) NOT NULL DEFAULT 'default',
  `Controller` varchar(50) NOT NULL DEFAULT 'index',
  `Action` varchar(100) NOT NULL DEFAULT 'index',
  `CateID` int(11) NOT NULL DEFAULT '0',
  `Status` tinyint(4) DEFAULT '1' COMMENT '1:active, 0:deleted', 
     */



    public function __construct()
    {
        $this->LayoutName     = '';
        $this->SectionName    = '';
        $this->Module         = '';
        $this->Controller     = '';
        $this->Action = '';
        $this->CateID = 0;
        $this->MapParams = '';
        $this->MapName = '';
        $this->MapLayout = '';
        $this->MapOrder = 0;
        $this->CreateDate     = 0;
        $this->ModifyDate     = 0;
        $this->Status = 0;
    }

    public function __destruct()
    {
        unset($this->LayoutName, $this->SectionName, $this->Module, $this->MapOrder,
              $this->Controller, $this->Action, $this->CateID, $this->CreateDate, 
              $this->ModifyDate, $this->Status,$this->MapParams, $this->MapName , $this->MapLayout);
    }

    /**
     * Init data
     * @param array $entity (LayoutID,LayoutName,LayoutTitle,LayoutView,CreateDate,ModifyDate,Status)
     * @return  Fpt_Bussiness_Block_block_metadata_layout
     */
    public function init($entity)
    {
        
        $this->LayoutName   = isset($entity['LayoutName'])?$entity['LayoutName']:'';
        $this->SectionName  = isset($entity['SectionName'])?$entity['SectionName']:'';
        $this->Module       = isset($entity['Module'])?$entity['Module']:'';
        $this->Controller   = isset($entity['Controller'])?$entity['Controller']:'';
        $this->Action       = isset($entity['Action'])?$entity['Action']:'';
        $this->CateID       = intval($entity['CateID']);
        $this->MapParams    = isset($entity['MapParams'])?$entity['MapParams']:'';
        //Rule map name: $layoutName.'_'.SectionName.'_'.$cateID.'_'.$module.'_'.$controller.'_'.$action.'_'.
//        $this->MapName      = $this->LayoutName;
//        $this->MapName      .= '_'.$this->SectionName;
        $this->MapName      .= '_'.$this->Module;
        $this->MapName      .= '_'.$this->Controller;
        $this->MapName      .= '_'.$this->Action;
        $this->MapName      .= '_'.$this->CateID;
        $this->MapName      = md5($this->MapName);
        
        $this->MapLayout    = $this->CateID;
        $this->MapLayout    .= '_'.$this->Module;
        $this->MapLayout    .= '_'.$this->Controller;
        $this->MapLayout    .= '_'.$this->Action;
   
        
        $this->MapOrder     = isset($entity['MapOrder'])?intval($entity['MapOrder']):0;
        $this->Status       = isset($entity['Status'])?intval($entity['Status']):0;
        $this->ModifyDate   = isset($entity['ModifyDate'])?intval($entity['ModifyDate']):0;
        $this->Status       = isset($entity['Status'])?intval($entity['Status']):0;
        return $this;
    }

    /**
     * Format data
     * @return array 
     */
    public function getData()
    {
        return array(
            'LayoutName'    => $this->LayoutName,
            'SectionName'   => $this->SectionName,
            'Module'        => $this->Module,
            'Controller'    => $this->Controller,
            'Action'        => $this->Action,
            'CateID'        => $this->CateID,
            'CreateDate'    => $this->CreateDate,
            'ModifyDate'    => $this->ModifyDate,
            'Status'        => $this->Status,
            'MapName'       => $this->MapName,
            'MapOrder'      => $this->MapOrder,
            'MapParams'     => $this->MapParams,
            'MapLayout' => $this->MapLayout,
        );
    }
    /**
     * 
     * @return type 
     */
    public function getDataCache()
    {
        return array(
            'LayoutName'    => $this->LayoutName,
            'SectionName'   => $this->SectionName,
            'Module'        => $this->Module,
            'Controller'    => $this->Controller,
            'Action'        => $this->Action,
            'CateID'        => $this->CateID,
            'MapParams'     => $this->MapParams,
            'MapName'       => $this->MapName,
            'MapOrder'      => $this->MapOrder,
            'MapLayout' => $this->MapLayout,
        );
    }
}